#ifndef SMS_SERVER_H_
#define SMS_SERVER_H_

#include <thread>

class evconnlistener;
class WorkGroup;
struct event_base;

// @brief 服务端
class SmsServer
{
public:
    /// @brief 构造函数
    /// @param port 端口
    /// @param thread_num 启动线程数量
    /// @param backlog 套接字内部缓存
    SmsServer(int port, int thread_num = 8, int backlog = 64);
    /// @brief 服务端初始化
    /// @return 初始化结果
    bool Init();
    /// @brief 启动
    void Start();
    /// @brief 停止
    void Stop();
    /// @brief 分发任务
    void Dispatch();
    /// @brief 新连接回调
    /// @param socket 对端socket
    void ConnListener(int socket);
    virtual ~SmsServer();
    /// @brief
    std::thread* GetThread() const;

private:
    int port_ = 0;
    int thread_num_ = 0;
    event_base *ev_base_ = nullptr;
    evconnlistener *ev_listener_ = nullptr;
    int backlog_ = 0;
    WorkGroup *boss_ = nullptr;              // 线程组
    std::thread *dispatch_thread_ = nullptr; // 内部运行线程
    bool server_quit_ = false;               // 服务退出标识
};

#endif
